﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using homework5;

namespace OrderWinform
{
    public partial class FormEditOrder : System.Windows.Forms.Form
    {
        public OrderService os;
        public Order selectOrder;
        public FormEditOrder(OrderService os,Order order)
        {
            InitializeComponent();
            try
            {
                this.os = os;
                selectOrder = order;
                txtID.Text = selectOrder.OrderId.ToString();
                txtCustomer.Text = selectOrder.Customer.Name;
                Customer customer = selectOrder.Customer;
                txtID.DataBindings.Add("Text", selectOrder, "Num");
                txtCustomer.DataBindings.Add("Text", customer, "Name");
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show("修改不正确");
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            os.Amend(os.SearchByNum(selectOrder.OrderId), int.Parse(txtID.Text));
            os.Amend(os.SearchByNum(selectOrder.OrderId), new Customer(selectOrder.CustomerId, txtCustomer.Text, selectOrder.Customer.Sex, selectOrder.Customer.Age, selectOrder.Customer.Tel));
            this.Close();
        }
    }
}
